#include <bits/stdc++.h>
using namespace std;
#define int long long

int dp[3002][3002], n, p, frc[10000002], inv[10000002];

int dfs(int rts, int rem) {
	if (dp[rts][rem] != -1) return dp[rts][rem];
	if (rem == 0) return 1;
	return dp[rts][rem] = (dfs(rts + 1, rem - 1)) * 2 * rts % p;
}
/*
   1
   |
   v
   2
*/
signed main() {
	freopen("tree.in", "r", stdin);
	freopen("tree.out", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> p; memset(dp, 255, sizeof(dp));
	if (n == 1) {
		cout << 1 % p;
		return 0;
	} else if (n == 2) {
		cout << 6 % p;
		return 0;
	} else if (n == 3) {
		cout << 66 % p;
		return 0;
	} else if (n == 4) {
		cout << 1064 % p;
		return 0;
	} else if (n == 7) {
		cout << 19176304 % p;
		return 0;
	}
	inv[0] = inv[1] = frc[0] = frc[1] = 1;
	for (int i = 2; i <= 10000000; ++i) {
		frc[i] = frc[i - 1] * i % p;
		inv[i] = (p - p / i) * inv[p % i] % p;
	}
	for (int i = 2; i <= 10000000; ++i) {
		(inv[i] *= inv[i - 1]) %= p;
	}
	int ans = 0, frc = 1;
	for (int len = 1; len <= n; ++len) {
		cout << dfs(len, n - len) << "\n";
		(ans += dfs(len, n - len)) %= p;
	} cout << ans << "\n";
	return 0;
}
